package com.omazan.srvlts;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.omazan.facace.ManageUserSession;
import com.omazan.facace.models.UserSessionDetails;
import com.omazan.utils.OmazanException;

/**
 * Servlet implementation class Login
 */
@WebServlet("/Login")
public class Login extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Login() {
        super();
        
    }

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String userName = request.getParameter("userName");
		String userPassword = request.getParameter("userPassword");
		
		try {
			UserSessionDetails userSessionDetails = new ManageUserSession().loginUser(userName, userPassword);
			request.getSession().setAttribute("userSessionDetails",userSessionDetails);
			response.sendRedirect("index.jsp");
		} catch (OmazanException e) {
			
			e.printStackTrace();
		}
		
       
	}

}
